package com.zking.ssm.controller;

import com.zking.ssm.model.HotelBrand;
import com.zking.ssm.model.HotelBrandType;
import com.zking.ssm.service.IHotelBrandService;
import com.zking.ssm.service.IHotelBrandTypeService;
import com.zking.ssm.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController  //返回json格式的数据
@RequestMapping("/Type") //窄化路径

public class HotelBrandTypeController {

    @Autowired
    private IHotelBrandTypeService iHotelBrandTypeService;
    @RequestMapping("/list")
    public Map<String,Object> list(HotelBrandType hotelBrandType){
        PageBean pageBean = new PageBean();
        List<HotelBrandType> list = iHotelBrandTypeService.SelectAll(hotelBrandType, pageBean);
        Map<String,Object> map = new HashMap<>();
        if(list.size() >= 0){
            map.put("code",0);
            map.put("message","查询品牌类型成功！");
            map.put("request",list);
        }else{
            map.put("code",-1);
            map.put("message","查询品牌类型失败！");
        }
        return map;
    }

    @RequestMapping("/add")
    public Map<String,Object> add(HotelBrandType hotelBrandType){
        int n = iHotelBrandTypeService.insert(hotelBrandType);
        Map<String,Object> map = new HashMap<>();
        if(n > 0){
            map.put("code",0);
            map.put("message","增加品牌类型成功！");
        }else{
            map.put("code",-1);
            map.put("message","增加品牌类型失败！");
        }
        return map;
    }

    @RequestMapping("/del")
    public Map<String,Object> del(HotelBrandType hotelBrandType){
        int n = iHotelBrandTypeService.deleteByPrimaryKey(hotelBrandType.getId());
        Map<String,Object> map = new HashMap<>();
        if(n > 0){
            map.put("code",0);
            map.put("message","删除品牌类型成功！");
        }else{
            map.put("code",-1);
            map.put("message","删除品牌类型失败！");
        }
        return map;
    }

    @RequestMapping("/update")
    public Map<String,Object> update(HotelBrandType hotelBrandType){
        int n = iHotelBrandTypeService.updateByPrimaryKeySelective(hotelBrandType);
        Map<String,Object> map = new HashMap<>();
        if(n > 0){
            map.put("code",0);
            map.put("message","修改品牌类型成功！");
        }else{
            map.put("code",-1);
            map.put("message","修改品牌类型失败！");
        }
        return map;
    }

    @RequestMapping("/get")
    public Map<String,Object> get(HotelBrandType hotelBrandType){
        HotelBrandType user = iHotelBrandTypeService.selectByPrimaryKey(hotelBrandType.getId());
        Map<String,Object> map = new HashMap<>();
        if(user != null){
            map.put("code",0);
            map.put("message","查询品牌类型成功！");
            map.put("request",user);
        }else{
            map.put("code",-1);
            map.put("message","查询品牌类型失败！");
        }
        return map;
    }

}
